<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>陕西人才知识管理</title>
<script type="text/javascript">
	var urL;
	function delRoleList() {
		//获得选中数据对象
		var selectedRows = $("#dg").datagrid('getSelections');
		if (selectedRows.length == 0) {
			$.messager.alert("系统提示", "请选择要删除的数据！");
			return;
		}
		var strIds = [];//要删除的序号组合
		for (var i = 0; i < selectedRows.length; i++) {
			strIds.push(selectedRows[i].roleid);
		}
		var ids = strIds.join(",");
		$.messager.confirm("系统提示", "您确认要删掉这<font color=red>"
				+ selectedRows.length + "</font>条数据吗？", function(r) {
			if (r) {
				//ajax提交 delIds
				$.post("delRoleList", {
					roleids : ids
				}, function(result) {
					if (result) {
						$.messager.alert("系统提示", "您已成功删除<font color=red>"
								+ selectedRows.length + "</font>条数据！");
						$("#dg").datagrid("reload");
					} else {
						$.messager.alert('系统提示', "删除失败");
					}
				}, "json");
			}
		});
	}
	
	function delRoleSingle(index){
			
			$("#dg").datagrid('selectRow',index);
			var row = $('#dg').datagrid('getSelected');
			$.messager.confirm("系统提示","您确认要删掉这<font color=red>1条</font>条数据吗？",function(r){
				if(r){
					//ajax提交 delIds
					$.post("delRole",{roleid:row.roleid},function(result){
						if(result){
							$.messager.alert("系统提示","您确认要删掉这<font color=red>1条</font>条数据吗？");
							$("#dg").datagrid("reload");
						}else{
							$.messager.alert('系统提示',"删除失败");
						}
					},"json");
				}
			});
		}
	//查询符合条件的用户
	function searchRole() {
		$('#dg').datagrid('load', {
			rolename : $('#rolename').val(),
		});
	}
	
	function reset(){
		
		$('#mrole').val("");
		$('#mrolename').val("");
		$('#mroledescription').val("");
	}
	function openRoleAddDialog(){
		reset();
		$("#dlg").dialog("open").dialog("setTitle","添加权限信息");
		urL = "addRole";
	}
	function openRoleModifyDialog(index) {
		$('#dg').datagrid('selectRow',index);
		var row = $('#dg').datagrid('getSelected');
		$("#dlg").dialog("open").dialog("setTitle", "编辑权限信息");
		$("#mroleid").val(row.roleid);
		$("#mrolename").val(row.rolename);
		$("#mroledescription").val(row.roledescription);
		urL= "updateRole";
	}
	function saveRole() {
		$("#fm").form("submit", {
			url : urL,
			onSubmit : function() {
				if ($('#mrolename').val() == "") {
					$.messager.alert("系统提示", "请输入角色名称");
					return false;
				}
				if ($('#mroledescription').val() == "") {
					$.messager.alert("系统提示", "请输入角色描述");
					return false;
				}
				return $(this).form("validate");
			},
			success : function(result) {
				if (result) {
					$.messager.alert("系统提示", "保存成功");
					$("#dlg").dialog("close");
					$("#dg").datagrid("reload");
				} else {
					$.messager.alert("系统提示", "保存失败");
					return;
				}
			}
		});
	}

	function formatOper(val, row, index) {
		
		return '<a href="#" onclick="delRoleSingle('
				+ index
				+ ')">删除</a>&nbsp<a href="#" onclick="openRoleModifyDialog('
				+ index + ')">修改</a>';
	}

	//关闭对话框
	function closeMessageDialog() {
		$("#dlg").dialog("close");
	}
</script>
<link rel="stylesheet" type="text/css"
	href="../../easyui-1.5/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css"
	href="../../easyui-1.5/themes/icon.css" />
<script type="text/javascript" src="../../easyui-1.5/jquery.min.js"></script>
<script type="text/javascript"
	src="../../easyui-1.5/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="../../easyui-1.5/locale/easyui-lang-zh_CN.js"></script>
</head>
<body style="margin: 5px">
	<table id="dg" title="角色信息" class="easyui-datagrid" fitColumns="true"
		striped="true" pagination="true" rownumbers="true"
		url="getRoleList" fit="true" toolbar="#tb" >
		<thead>
			<tr>
				<th field="cb" checkbox="true"></th>
				<th field="roleid" width="100" align="center" hidden="true"></th>
				<th field="rolename" width="100" align="center">角色名称</th>
				<th field="roledescription" width="100" align="center">角色描述</th>
				<th field="roletime" width="100" align="center">创建时间</th>
				<th field="_operate" width="100" align="center" formatter="formatOper">操作</th>
			</tr>
		</thead>
	</table>
	<div id="tb" style="padding-bottom: 15px; padding-top: 15px">
		<div>
			<form method="post">
				&nbsp;角色名称：&nbsp;<input type="text" name="rolename"
					id="rolename" size="20" style="width:300px" /> 
					<a href="javascript:searchRole()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
					<a href="javascript:openRoleAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
					<a href="javascript:delRoleList()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
					
			</form>
		</div>
	</div>
	<div id="dlg" class="easyui-dialog"
		style="width: 400px; height: 180px; padding: 10px 20px" closed="true"
		buttons="#dlg-buttons">
		<form id="fm" method="post">
			<input type="text" name="roleid" id="mroleid" hidden="true"/>
			<table cellspacing="5px;">
				<tr>
					<td>角色名称：</td>
					<td><input type="text" name="rolename" id="mrolename"
						class="easyui-validatebox" required="true" style="width:250px" /></td>
				</tr>
				<tr>
					<td>角色描述：</td>
					<td><input class="easyui-validatebox" name="roledescription"
						id="mroledescription"  required="true" style="width:250px"/></td>
				</tr>
			</table>
		</form>
	</div>

	<div id="dlg-buttons">
			<a href="javascript:saveRole()" class="easyui-linkbutton"
			iconCls="icon-ok">保存</a> 
			<a href="javascript:reset()" class="easyui-linkbutton"
			iconCls="icon-ok">重置</a>
			<a href="javascript:closeMessageDialog()"
			class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
	</div>

</body>
</html>